// File: src/core/tasks/Task.h
#pragma once
#include <string>
#include <ctime>
#include <iomanip>
#include <sstream>

enum class Priority { LOW, MEDIUM, HIGH };
enum class Category { STUDY, ENTERTAINMENT, LIFE, WORK };

class Task {
public:
    Task(const std::string& name, std::time_t startTime,
        Priority priority = Priority::MEDIUM,
        Category category = Category::LIFE,
        std::time_t remindTime = 0)
        : id(nextId++), name(name), startTime(startTime),
        priority(priority), category(category),
        remindTime(remindTime) {}

    // Get函数
    int getId() const { return id; }
    void setId(const int& num) { id = num;} 
    const std::string& getName() const { return name; }
    std::time_t getStartTime() const { return startTime; }
    Priority getPriority() const { return priority; }
    Category getCategory() const { return category; }
    std::time_t getRemindTime() const { return remindTime; }
    bool isReminded() const { return reminded; }

    // Set函数
    void markReminded() { reminded = true; }

    // Helper methods
    std::string getFormattedStartTime() const {
        char buffer[20];
        std::strftime(buffer, sizeof(buffer), "%Y-%m-%d %H:%M", std::localtime(&startTime));
        return buffer;
    }

    std::string getPriorityString() const {
        switch (priority) {
        case Priority::LOW: return "低";
        case Priority::MEDIUM: return "中";
        case Priority::HIGH: return "高";
        default: return "未知";
        }
    }

    std::string getCategoryString() const {
        switch (category) {
        case Category::STUDY: return "学习";
        case Category::ENTERTAINMENT: return "娱乐";
        case Category::LIFE: return "生活";
        case Category::WORK: return "工作";
        default: return "未知";
        }
    }

    bool shouldRemind(std::time_t now) const {
        return !reminded && remindTime > 0 && now >= remindTime;
    }

    static std::time_t parseDateTime(const std::string& datetimeStr);

private:
    static int nextId;  // 只声明，不移除初始化
    int id;
    std::string name;
    std::time_t startTime;
    Priority priority;
    Category category;
    std::time_t remindTime;
    bool reminded = false;
};

